import Taro, { Component } from '@tarojs/taro';
import { View, ScrollView, Image, Text } from '@tarojs/components';
import { DNavBar, DTabs, DItemError } from '@/components';
import { AtSearchBar, AtList,AtListItem } from 'taro-ui'
import './allStatics.scss';
import http from '@/api'

export default class InventoryManage extends Component {
  state = {
    titleIcon: require('@/assets/images/inventory_icon.png'),
    rightArrowIcon: require('@/assets/images/right_arrow_icon.png'),
    tabs: [{
      name: '已盘库',
      value: 2
    }, {
      name: '已处理',
      value: 9
    }],
    list: [],
    tabIndex: 2,
    totalPage: 0,
    form: {
      page: 1,
      limit: 10
    },
    inputVal: ''
  }
  componentDidShow() {
    this.getStocktakingList()
  }
  onScrollToLower = () => {
    this.setState({ form: {
      ...this.state.form,
      page: this.state.form.page + 1
    }}, this.getStocktakingList)
  }
  getStocktakingList() {
    const { form, tabIndex: status } =  this.state

    if (form.page != 1 && form.page > this.state.totalPage) return

    http.getAllSummary({limit: 20,page: 0}).then( res => {
      // if (form.page === 1) {
      //   this.setState({ list, totalPage })
      // } else {
      //   this.setState({ list: [...this.state.list, ...list], totalPage })
      // }
      this.setState({ list: res.allSummary }, () => {
        console.log(this.state.list)
      })
      console.log(res)
    })
  }
  handleTabClick = (index) => {
    this.setState({
      tabIndex: index,
      list: [],
      form: {
        ...this.state.form,
        page: 1
      }
    }, this.getStocktakingList)
  }
  handleItemClick = (id) => {
    Taro.navigateTo({ url: '/pages/historyOrder/detail?id=' + id })
  }
  handleStatusText(status) {
    return {
      1: '待审核',
      2: '审核通过',
      3: '审核不通过',
      4: '待放盘库',
	  5: '资料不全',
	  5: '盘库完成',
    }[status]
  }
  searchValChange = (val) => {
    this.setState({ searchVal: val.trim() })
  }
  onClear = () => {
    let form = this.state.form
    form.content = ''
    this.setState({ searchVal: '', form })
  }
  onActionClick = () => {
    this.setState({
      form: {
        ...this.state.form,
        page: 1,
        content: this.state.searchVal
      }
    }, this.getStocktakingList)
  }

  render() {
    const { tabs, list, tabIndex, titleIcon, rightArrowIcon, searchVal } = this.state;

    return (
      <View className="allStatics">
        <DNavBar title="汇总"></DNavBar>
		<AtList hasBorder={false}>
		 <AtListItem
		     title={'全部汇总信息'}
		  	 className={'ListItemBg'}
		      thumb={require('../assets/historyOrder/info0.png')}
		  			  
		  	/>
		 
		</AtList>
		<View className="allStatics__body">	
         <View className='at-row  between'>
           <View className='at-col year t-center pad'>年份</View>
           <View className='at-col t-center pad'>车商数量</View>
           <View className='at-col t-center pad'>合同款总额</View>
		   <View className='at-col t-center pad'>垫资总额</View>
		   <View className='at-col t-center pad'>订单量总额</View>
         </View>
        <ScrollView scrollY className="allStatics__body_info" onScrollToLower={this.onScrollToLower}>
          {
            list.map(item => (
              <View className='at-row between'>
                <View className='at-col t-center pad'>{item.years}</View>
                <View className='at-col t-center pad'>{item.numberOfCarDealers}</View>
                <View className='at-col t-center pad'>{item.totalContracts} 万</View>
                <View className='at-col t-center pad'>{item.totalAdvances} 万</View>
                <View className='at-col t-center pad'>{item.totalNumberOfOrders}</View>
              </View>
            ))
          }
		  {/* <View className='at-row between'>
		    <View className='at-col t-center pad'>2</View>
		    <View className='at-col t-center pad'>23</View>
		    <View className='at-col t-center pad'>345</View>
		    <View className='at-col t-center pad'>56</View>
		    <View className='at-col t-center pad'>544</View>
		  </View>
		  <View className='at-row between'>
		    <View className='at-col t-center pad'>2</View>
		    <View className='at-col t-center pad'>23</View>
		    <View className='at-col t-center pad'>345</View>
		    <View className='at-col t-center pad'>56</View>
		    <View className='at-col t-center pad'>544</View>
		  </View> */}
          {/* {
            list.length === 0 && <DItemError type={searchVal ? 2 : 1}></DItemError>
          } */}
		
        </ScrollView>
		    </View>
      </View>
    )
  }
}
